﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;

namespace Main.Reseau
{
    public enum EtatsConnexion
    {
        ConnexionEtablie,
        EnAttente

    }
    public class Connexion
    {
        private static List<Connexion> listeConnexions = new List<Connexion>();

        private byte idConnexionLogique;
        private EtatsConnexion etat;
        private byte adresseSource;
        private byte adresseDestination;
        private int pr;
        private int ps;
        private Timer timer;

        private Connexion(byte adresseSource, byte adresseDestination)
        {
            if (listeConnexions.Count > 0)
                this.idConnexionLogique = (byte)(listeConnexions.Max(c => c.idConnexionLogique) + 1);
            else
                this.idConnexionLogique = 1;

            this.etat = EtatsConnexion.EnAttente;
            this.adresseSource = adresseSource;
            this.adresseDestination = adresseDestination;
            this.pr = 0;
            this.ps = 0;
        }

        public byte IdConnexionLogique { get { return idConnexionLogique; } }
        public EtatsConnexion Etat { get { return etat; } set { etat = value; } }
        public byte AdresseSource { get { return adresseSource; } }
        public byte AdresseDestination { get { return adresseDestination; } }
        public static List<Connexion> ListeConnexions { get { return listeConnexions.ToList(); } }

        public static Connexion CreateConnexion(byte adresseSource, byte adresseDestination)
        {
            Connexion connexion = new Connexion(adresseSource, adresseDestination);
            listeConnexions.Add(connexion);
            return connexion;
        }

        public static void DeleteConnexion(Connexion connexion)
        {
            listeConnexions.Remove(connexion);
        }

        public int GetPS()
        {
            if (ps < 8)
                ps++;
            else
                ps = 0;
            return ps;
        }

        public int GetPR()
        {
            if (pr < 8)
                pr++;
            else
                pr = 0;
            return pr;
        }


    }
}
